import re
'''
给你一串字符串，判断这是否是手机号码
'''

def chechPhone(str):
    if len(str) != 11:
        return False
    elif str[0] != "1":
        return False
    elif str[1:3] != "39" and str[1:3] != "31":
        return False
    for i in range(3, 11):
        if str[i] < "0" or str[i] > "9":
            return False
    return True

def chechPhone2(str):
    #13912345678
    pat = r"^1(([3578]\d)|(47))\d{8}$"
    res = re.match(pat, str)
    return res


print(chechPhone2("13912345678"))
print(chechPhone2("139123456785"))
print(chechPhone2("1391234a678"))
print(chechPhone2("23912345678"))
print(chechPhone2("19012345678"))

'''
提取手机号码
'''

def chechPhone3(str):
    #13912345678
    pat = r"(1(([3578]\d)|(47))\d{8})"
    res2 = re.findall(pat, str)
    print(res2)


print(chechPhone3("dgrgr13912345678thtj13955555555fdhgtrft13578888888ergrg"))




'''
QQ  6到10位，全是数字
'''
re_QQ = re.compile(r"^[1-9]\d{5,9}$")
print(re_QQ.search("123456789"))